import { TreeSelect } from "antd";
import React, { useState } from "react";
import Notfound from "../notFound/not-found";
const XxtreeSelect = (props) => {

    const { treeData, fieldNames, defaultValue, placeholder = "", allowClear = false } = props
    const [treeLine, setTreeLine] = useState(true);
    const [showLeafIcon, setShowLeafIcon] = useState(false);
    return (
        <>
            <TreeSelect
                fieldNames={fieldNames}
                showSearch
                treeLine={
                    treeLine && {
                        showLeafIcon,
                    }
                }
                style={{
                    width: '100%',
                    flex: 1
                }}
                dropdownStyle={{
                    maxHeight: 400,
                    overflow: 'auto',
                }}

                placeholder={placeholder}
                allowClear={allowClear}
                notFoundContent={<Notfound />}
                treeData={treeData}
                defaultValue={defaultValue}//传入当前默认值
                treeDefaultExpandAll={false}
                filterTreeNode={(input, option) => {
                    return (option[fieldNames.label] ?? "").toLowerCase().includes(input.toLowerCase()) || (option[fieldNames.value] ?? "").toLowerCase().includes(input.toLowerCase());
                }}
                {...props}


            />
        </>
    )

}

export default XxtreeSelect